package testcases;

import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.Test;

import code.SavingsAccount;

public class SavingsAccountTest {
	SavingsAccount account;
	
	public void runTest() {
		account = new SavingsAccount("Billy", "1 main st.", "12345","Seattle", "USA");
		testFields();
		testCalculateInterest();
		testWithdrawal();
		testVerseMoney();
		testPrint();
	}
	
	public void testFields(){
		assertEquals("Billy", account.fName);
		assertEquals("1 main st.", account.fStreet);
		assertEquals("12345", account.fZipCode);
		assertEquals("Seattle", account.fTown);
		assertEquals("USA", account.fCountry);
		assertEquals(1, account.fAccountNumber);
	}
	
	public void testCalculateInterest(){
		account.calculateInterest();
		assertEquals(0.0, account.fBalance, 0.0);
	}
	
	public void testWithdrawal(){
		assertFalse(account.withdrawal(10.00));
		
		account.fBalance = 100.00;
		assertTrue(account.withdrawal(50.00));
		assertTrue(account.withdrawal(50.00));
		assertFalse(account.withdrawal(50.00));
	}
	
	public void testVerseMoney(){
		account.verseMoney(100.00);
		assertEquals(100.00, account.fBalance, 100.00);
	}
	
	public void testPrint(){
		ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));

		String account_info = "**************************************\n"
				+ "Savings account:     1\n"
				+ "Account holder name: Billy\n"
				+ "Address:             1 main st.\n"
				+ "                     12345 Seattle\n"
				+ "USA\n"
				+ "**************************************\n"
				+ "Balance:  100.0\n"
				+ "**************************************\n";
	
		account.print();
		assertEquals(account_info, outContent.toString());

	}

}
